package com.gxa.www.cl.controller;



import com.gxa.www.cl.domain.vo.PurchaseOrders;
import com.gxa.www.cl.service.PurchaseDetailService;
import com.gxa.www.cl.common.util.PurchaseDetail;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class PurchaseDetailController {

    @Autowired
    private PurchaseDetailService purchaseDetailService;

    // 获取采购单信息
    @GetMapping("/purchaseDetails")
    public List<PurchaseDetail> getPurchaseDetails() {
//        System.out.println(purchaseDetailService.getPurchaseOrders().toString());
        return purchaseDetailService.getPurchaseDetails();
    }

    // 添加采购明细
    @PostMapping("/addPurchaseDetail")
    public String addPurchaseDetail(@RequestBody PurchaseDetail purchaseDetail) {
        return purchaseDetailService.addPurchaseDetail(purchaseDetail);
    }

    // 获取药品类别
    @GetMapping("/medicineCategories")
    public List<String> getMedicineCategories() {
        return purchaseDetailService.getMedicineCategories();
    }

    // 根据类别获取药品
    @GetMapping("/medicines")
    public List<String> getMedicinesByCategory(@RequestParam String category) {
        return purchaseDetailService.getMedicinesByCategory(category);
    }

    //获取采购列表
    @GetMapping("/PurchaseOrders")
    public List<PurchaseOrders> getPurchaseOrders() {
        return purchaseDetailService.getPurchaseOrders();
    }

    //删除采购列表
    @DeleteMapping("/PurchaseOrders/{id}")
    public String DeletePurchaseOrders(@PathVariable Integer id) {
        purchaseDetailService.DeletePurchaseOrders(id);
        return "1";
    }

    //修改采购列表
    @PutMapping("/PurchaseOrders")
    public String UpdatePurchaseOrders(@RequestBody PurchaseOrders purchaseOrders) {
        System.out.println("=======修改=======");
        System.out.println(purchaseOrders.toString());
        purchaseDetailService.UpdatePurchaseOrders(purchaseOrders);
        return "1";
    }
}
